package com.ruoyi.park.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.park.domain.MaMaterialReport;
import com.ruoyi.park.service.IMaMaterialReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 物资月报Controller
 *
 * @author felix
 * @date 2022-06-12
 */
@Api(tags = " 物资月报")
@RestController
@RequestMapping("/maMaterialReport")
public class MaMaterialReportController extends BaseController {
    @Autowired
    private IMaMaterialReportService maMaterialReportService;

    /**
     * 查询物资月报列表
     */
    @ApiOperation(value="查询物资月报列表", notes="查询物资月报列表")
    @PreAuthorize(hasPermi = "park:maMaterialReport:list")
    @GetMapping("/list")
    public TableDataInfo list(MaMaterialReport maMaterialReport) {
        startPage();
        List<MaMaterialReport> list = maMaterialReportService.selectMaMaterialReportList(maMaterialReport);
        return getDataTable(list);
    }

    /**
     * 导出物资月报列表
     */
    @ApiOperation(value="导出物资月报列表", notes="导出物资月报列表")
    @PreAuthorize(hasPermi = "park:maMaterialReport:export")
    @Log(title = "物资月报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaMaterialReport maMaterialReport) throws IOException {
        List<MaMaterialReport> list = maMaterialReportService.selectMaMaterialReportList(maMaterialReport);
        ExcelUtil<MaMaterialReport> util = new ExcelUtil<MaMaterialReport>(MaMaterialReport.class);
        util.exportExcel(response, list, "物资月报数据");
    }
    /**
     * 获取物资月报详细信息
     */
    @ApiOperation(value="获取物资月报详细信息", notes="获取物资月报详细信息")
    @PreAuthorize(hasPermi = "park:maMaterialReport:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(maMaterialReportService.selectMaMaterialReportById(id));
    }

    /**
     * 新增物资月报
     */
    @ApiOperation(value="新增物资月报", notes="新增物资月报")
    @PreAuthorize(hasPermi = "park:maMaterialReport:add")
    @Log(title = "物资月报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaMaterialReport maMaterialReport) {
        return toAjax(maMaterialReportService.insertMaMaterialReport(maMaterialReport));
    }

    /**
     * 修改物资月报
     */
    @ApiOperation(value="修改物资月报", notes="修改物资月报")
    @PreAuthorize(hasPermi = "park:maMaterialReport:edit")
    @Log(title = "物资月报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaMaterialReport maMaterialReport) {
        return toAjax(maMaterialReportService.updateMaMaterialReport(maMaterialReport));
    }

    /**
     * 删除物资月报
     */
    @ApiOperation(value="删除物资月报", notes="删除物资月报")
    @ApiImplicitParam(name = "ids", value = "物资月报ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "park:maMaterialReport:remove")
    @Log(title = "物资月报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(maMaterialReportService.deleteMaMaterialReportByIds(ids));
    }



}
